﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using ACompany.OrderProcessing.Presentation.Product;

public partial class Product_ProductList : UserControl , IProductListView
{
    private ProductListPresenter _presenter;

    private void Page_Init(object sender, EventArgs e)
    {
        _presenter = new ProductListPresenter(this);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        _presenter.Display();
    }

    public List<ACompany.OrderProcessing.Model.Product> Products
    {
        set
        {
            this.grdProducts.DataSource = value;
            this.grdProducts.DataBind();
        }
    }

    protected void btnAddProduct_Click(object sender, EventArgs e)
    {
        Response.Redirect("ProductDetail.aspx?Action=Detail");
    }

    protected void grdProducts_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName.ToLower())
        {
            case "deleteproduct":
                _presenter.RemoveProductBy(new Guid(e.CommandArgument.ToString()));
                break;
        }
    }

    public void ErrorMessage(string Message)
    {
        if (string.IsNullOrEmpty(Message))
        {
            pnlError.Visible = false;
        }
        else
        {
            pnlError.Visible = true;
        }
        if (Message != null) this.litErrorMessage.Text = Message.Replace(Environment.NewLine, "<br/>");
    }

    public void InfoMessage(string Message)
    {
        if (string.IsNullOrEmpty(Message))
        {
            pnlInfo.Visible = false;
        }
        else
        {
            pnlInfo.Visible = true;
        }
        if (Message != null) this.litInfoMessage.Text = Message.Replace( Environment.NewLine, "<br/>");
    }


    public void ViewTitle(string title)
    {
    }
}